<%@ page language="java" import="java.util.*,dao.*,dao.impl.*,entity.*" pageEncoding="utf-8"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%
    BoardDao boardDao = new BoardDaoImpl();
    TopicDao topicDao = new TopicDaoImpl();
    UserDao userDao = new UserDaoImpl();
    Map mapBoard = boardDao.findBoard();
%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <title>主页</title>
    <link rel="stylesheet" href="css/topbar.css">
    <link rel="stylesheet" href="css/index.css">
</head>
<body>
<div class="main">
    <div class="top">
        <label>校园BBS系统</label>
    </div>
    <%
        if(session.getAttribute("user") == null){
    %>
    <div class="bar"><p>您尚未
        <a href="login.jsp" target="_blank">登录</a>&nbsp;|
        <a href="register.jsp" target="_blank">注册</a>
    </p>
    </div>
    <%
    }
    else{
        User loginUser = (User)session.getAttribute("user");
    %>
    <p class ="bar">
        您好：<%= loginUser.getUName() %>&nbsp;|&nbsp;
        <a href ="login.jsp" target="_blank">登出</a>
    </p>
    <%	} %>
    <div class="table-style">
        <table id="table-set">
            <thead>
            <th colspan="2">论坛</th>
            <th class="theme">主题</th>
            <th>最后发表</th>
            </thead>
            <tbody>
            <tr>
                <!-- 主板块 -->
                <%
                    List listMainBoard = (List)mapBoard.get(new Integer(0));
                    for(int i = 0;i<listMainBoard.size();i++) {
                        Board mainBoard = ((Board) listMainBoard.get(i));//循环获得主版块

                %>
                <td colspan="4" class="top-tr"><%= mainBoard.getBoardName() %></td>
            </tr
                    <!--子版块  -->
                <%
        	List listSonBoard = (List)mapBoard.get(new Integer(mainBoard.getBoardId()));
        	for(int j = 0;j<listSonBoard.size();j++){
        		Board sonBoard = (Board)listSonBoard.get(j);
        		Topic topic = new Topic();
        		User user = new User();
        		int boardId = sonBoard.getBoardId();
        		List listTopic = topicDao.findListTopic(1, boardId);
        		if(listTopic!=null && listTopic.size()>0){
        		topic = (Topic)listTopic.get(0);
        		user = userDao.findUser(topic.getUid());

        		}

         %>

            <tr>
                <td width="5%">&nbsp;</td>
                <th>
                    <img  class="imgstyle" src="images/<%= boardId%>.jpg"/>
<%--                    <a href="list.jsp?page=1&boardID=<%= boardId %>"><%= sonBoard.getBoardName() %></a>--%>
                    <a href="ListServlet?page=1&boardID=<%= boardId %>"><%= sonBoard.getBoardName() %></a>
                </th>

                <td align="center"><%= topicDao.findCountTopic(boardId) %></td>
                <th>
				<span>
					<a href="detail.jsp?page=1&boardID=<%= boardId %>&topicID=<%= topic.getTopicId()%>"><%= topic.getTitle() %></a>
				</span>
                    <span style="padding-right: 10px;">作者:&nbsp;<%= user.getUName() %></span>
                    <span class="time-set">[<%= topic.getPublishTime() %>]</span>
                </th>
            </tr>

            <%
                    }
                }
            %>
<%--            <tr>--%>
<%--                <td>&nbsp;</td>--%>
<%--                <td>Winforms</td>--%>
<%--                <td>&nbsp;</td>--%>
<%--                <td>&nbsp;</td>--%>
<%--            </tr>--%>
<%--            <tr>--%>
<%--                <td>&nbsp;</td>--%>
<%--                <td>ADO.NET</td>--%>
<%--                <td>&nbsp;</td>--%>
<%--                <td>&nbsp;</td>--%>
<%--            </tr>--%>
<%--            <tr>--%>
<%--                <td>&nbsp;</td>--%>
<%--                <td>ASP.NET</td>--%>
<%--                <td>&nbsp;</td>--%>
<%--                <td>&nbsp;</td>--%>
<%--            </tr>--%>
<%--            <tr>--%>
<%--                <td colspan="4" class="top-tr">Java方向</td>--%>
<%--            </tr>--%>
<%--            <tr>--%>
<%--                <td>&nbsp;</td>--%>
<%--                <td>java基础</td>--%>
<%--                <td>&nbsp;</td>--%>
<%--                <td>&nbsp;</td>--%>
<%--            </tr>--%>
<%--            <tr>--%>
<%--                <td>&nbsp;</td>--%>
<%--                <td>jsp技术</td>--%>
<%--                <td>&nbsp;</td>--%>
<%--                <td>&nbsp;</td>--%>
<%--            </tr>--%>
<%--            <tr>--%>
<%--                <td>&nbsp;</td>--%>
<%--                <td>serviet技术</td>--%>
<%--                <td>&nbsp;</td>--%>
<%--                <td>&nbsp;</td>--%>
<%--            </tr>--%>
<%--            <tr>--%>
<%--                <td>&nbsp;</td>--%>
<%--                <td>ASP.NET</td>--%>
<%--                <td>&nbsp;</td>--%>
<%--                <td>&nbsp;</td>--%>
<%--            </tr>--%>
            </tbody>
        </table>
    </div>
</div>
</body>
</html>